//
//  FootPlayView.m
//  ProJectB_1
//
//  Created by lanou3g on 16/8/16.
//  Copyright © 2016年 yangshukai. All rights reserved.
//

#import "FootPlayView.h"

@implementation FootPlayView

- (void)setPlayViewModel:(PlayViewModel *)playViewModel{
    
    [_slider addTarget:self action:@selector(changeValueAction:) forControlEvents:(UIControlEventValueChanged)];
    _playViewModel = playViewModel;
    
}

- (void)changeValueAction:(id *)sender{
    PlayerManager *manager = [PlayerManager defaultManager];
    [manager seekToNewTime:_slider.value];
}

- (IBAction)lastMusic:(id)sender {
    [[PlayerManager defaultManager] lastMusic];
    //利用block将当前播放的单元传出 方便刷新播放的信息（图片 title等）
    if (_selectRadioBlock != nil) {
        _selectRadioBlock([PlayerManager defaultManager].playIndex);
    }
    // 将播放按钮变成暂停标识
    [self.playButton setImage:[UIImage imageNamed:@"暂停"] forState:UIControlStateNormal];
}

- (IBAction)playAndPause:(id)sender {
    PlayerManager *manager = [PlayerManager defaultManager];
    // 判断播放状态
    if (manager.playState == PlayerStatePlay) {
        [manager pause];
        // 改变标识
        [self.playButton setImage:[UIImage imageNamed:@"播放"] forState:UIControlStateNormal];
    }else{
        [manager play];
        // 改变标识
        [self.playButton setImage:[UIImage imageNamed:@"暂停"] forState:UIControlStateNormal];
    }

}

- (IBAction)nextMusic:(id)sender {
    [[PlayerManager defaultManager]nextMusic];
    //利用block将当前播放的单元传出 方便刷新播放的信息（图片 title等）
    if (_selectRadioBlock != nil) {
        _selectRadioBlock([PlayerManager defaultManager].playIndex);
    }
    // 将播放按钮变成暂停标识
    [self.playButton setImage:[UIImage imageNamed:@"暂停"] forState:UIControlStateNormal];
}
- (IBAction)changeType:(id)sender {

    if ([PlayerManager defaultManager].playType == PlayTypeSingle) {
        [PlayerManager defaultManager].playType = PlayTypeRandom;
        // 将模式按钮变成随机标识
        [self.typeButton setImage:[UIImage imageNamed:@"随机"] forState:(UIControlStateNormal)];
    }else if ([PlayerManager defaultManager].playType == PlayTypeRandom){
        [PlayerManager defaultManager].playType = PlayTypeList;
        // 将模式按钮变成循环标识
       
        [self.typeButton setImage:[UIImage imageNamed:@"循环"] forState:(UIControlStateNormal)];
    }else if ([PlayerManager defaultManager].playType == PlayTypeList){
        [PlayerManager defaultManager].playType = PlayTypeSingle;
        // 将随机按钮变成单曲标识
        
        [self.typeButton setImage:[UIImage imageNamed:@"单曲循环"] forState:(UIControlStateNormal)];
    }
}

@end
